package org.hadoop.seq;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.SequenceFile.Writer;
import org.apache.hadoop.io.Text;
/**
 * 保存一个顺序文件
 */
public class CreateSequenceFile {
    public static void main(String[] args) throws Exception {
        Configuration config = new Configuration();
        // 设置文件名和key value类型
        Writer.Option op1 = Writer.file(new Path("file:///D:/a/1.seq"));
        Writer.Option op2 = Writer.keyClass(IntWritable.class);
        Writer.Option op3 = Writer.valueClass(Text.class);
        SequenceFile.Writer w = SequenceFile.createWriter(config, op1, op2, op3);
        w.append(new IntWritable(1), new org.apache.hadoop.io.Text("Hello"));
        w.append(new IntWritable(20), new org.apache.hadoop.io.Text("Second Row"));
        w.append(new IntWritable(3), new org.apache.hadoop.io.Text("last Row"));
        w.close();
    }
}
